package ru.ifmo.automaton.generators;

import ru.ifmo.automaton.Automaton;
import ru.ifmo.automaton.SynchronizingAutomatonImpl;
import ru.ifmo.common.Source;

import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * Not thread safe!
 *
 * @author avhaliullin
 */
public abstract class AbstractAutomatonSource<C, S> implements Source<Automaton<C, S>> {

    public abstract void rebuild();

    protected abstract boolean needToRebuild();

    public Automaton<C, S> create() {
        if (needToRebuild()){
            rebuild();
        }
        return new SynchronizingAutomatonImpl<C, S>(
                getTransitions(),
                new HashSet<S>(),
                getInitial(),
                null,
                getAlphabet());
    }


    protected abstract List<C> getAlphabet();

    protected abstract S getInitial();

    protected abstract Map<S, Map<C, S>> getTransitions();
}
